$(function(){
    $('.product-navbar-collapse').on('click', function () {
        if ($('.viewFramework-product').hasClass('viewFramework-product-col-1')) {
            $('.viewFramework-product').removeClass('viewFramework-product-col-1')
        } else {
            $('.viewFramework-product').addClass('viewFramework-product-col-1')
        }
    });

    $('.sidebar-fold').on('click', function () {
        if ($('.viewFramework-body').hasClass('viewFramework-sidebar-full')) {
            $('.viewFramework-body').removeClass('viewFramework-sidebar-full')
            $('.viewFramework-body').addClass('viewFramework-sidebar-mini')
            $('.sidebar-fold').removeClass('icon-unfold')
            $('.sidebar-fold').addClass('icon-fold')
        } else {
            $('.viewFramework-body').addClass('viewFramework-sidebar-full')
            $('.viewFramework-body').removeClass('viewFramework-sidebar-mini')
            $('.sidebar-fold').removeClass('icon-fold')
            $('.sidebar-fold').addClass('icon-unfold')
        }
    });

    $('.sidebar-nav').on('click', function (event) {
        if ($(event.currentTarget).hasClass('sidebar-nav-active')) {
            $(event.currentTarget).removeClass('sidebar-nav-active')
            $(event.currentTarget).find('ul').css({
                maxHeight: '0px'
            })
        } else {
            $('.sidebar-nav-active').find('ul').css({
                maxHeight: '0px'
            })
            $('.sidebar-nav-active').removeClass('sidebar-nav-active')
            $(event.currentTarget).addClass('sidebar-nav-active')
            var liCount = $(event.currentTarget).find('li').length
            $(event.currentTarget).find('ul').css({
                maxHeight: (liCount * 30) + 'px'
            })
        }
    });

    $('.nav-item').on('click', function (event) {
        event.preventDefault()
        event.stopPropagation()
    })

    $('.product-nav-list ul li').on('click', function (event) {
        if ($(event.currentTarget).hasClass('nav-showchild')) {
            $(event.currentTarget).removeClass('nav-showchild')
            $(event.currentTarget).find('ul').addClass('ng-hide')
            $(event.currentTarget).find('.icon-arrow-down').addClass('icon-arrow-right')
            $(event.currentTarget).find('.icon-arrow-down').removeClass('icon-arrow-down')
        } else {
            $(event.currentTarget).addClass('nav-showchild')
            $(event.currentTarget).find('ul').removeClass('ng-hide')
            $(event.currentTarget).find('.icon-arrow-right').addClass('icon-arrow-down')
            $(event.currentTarget).find('.icon-arrow-right').removeClass('icon-arrow-right')
        }
    });

    $('.topbar-product').on('click', function (event) {
        if ($(event.currentTarget).hasClass('open')) {
            $(event.currentTarget).find('.topbar-product-dropdown').removeClass('topbar-show')
            $(event.currentTarget).removeClass('open')
        } else {
            $(event.currentTarget).find('.topbar-product-dropdown').addClass('topbar-show')
            $(event.currentTarget).addClass('open')
        }
        event.preventDefault()
        event.stopPropagation()
    });
    
    $('.topbar-product-nav-list li').on('mouseover', function (event) {
        $(event.currentTarget.parentNode).find('li').removeClass('active')
        $(event.currentTarget).addClass('active')
    })

    $('.topbar-product-container').on('click', function (event) {
        event.preventDefault()
        event.stopPropagation()
    })

    document.onclick = function () {
        $('.topbar-product').removeClass('open')
        $('.topbar-product .topbar-product-dropdown').removeClass('topbar-show')
    }
});